

    //倒计时秒杀功能
    var mskDivs=document.querySelectorAll('.msk_time span')
   
    function MSK(){
        var now=new Date() 
        var msktime=new Date('2021/3/8 18:00')
        var mskdiff=parseInt((msktime-now)/1000)
        var mskday = parseInt(mskdiff/(24*60*60)) ;//如果答案是2.4,天数就是2，不足一天的小数0.4会换算成小时
        mskdiff = mskdiff - mskday*24*60*60
        var mskhour = parseInt(mskdiff/3600);//如果答案是14.5,小时时14，不足一小时的0.5换算成分钟
        mskdiff = mskdiff - mskhour*3600
        // 1分钟 = 60秒
        var mskminute = parseInt(mskdiff/60);//如果答案是12.5,分钟时12，不足一分钟的换成秒
        var msksecond = mskdiff - 60*mskminute;
        mskDivs[0].innerHTML=mskhour
        mskDivs[1].innerHTML=mskminute
        mskDivs[2].innerHTML=msksecond
    }
    
    setInterval(function(){
        MSK()
    },1000)


    // 广告轮播图
    var slideDiv=document.getElementById('slideDiv')
    var slideprev=document.querySelector('.slideprev')
    
    var slidenext=document.querySelector('.slidenext')
    var slideimga=document.querySelectorAll('.slideimg a')
    var slideols=document.querySelectorAll('#slideDiv ol li span')
    var slideindex=0
    slidenext.onclick=function(){
        next()
    }
    $(slideDiv).hover(function(){
        clearInterval(slidetime)
    },function(){
        slidetime=setInterval(next,10000)
    })
    function showImg(slideindex) {
        for (var i = 0; i < slideimga.length; i++) {
            move(slideimga[i], "opacity", 0)
            slideols[i].style.backgroundColor="#424242"
        }
        move(slideimga[slideindex], "opacity", 100)
        slideols[slideindex].style.backgroundColor="#fff"
    }
    slideprev.onclick=function(){
        slideindex--
        if(slideindex<0){
            slideindex=slideimga.length-1
        }
    
        showImg(slideindex)
    }
    function next(){
        slideindex++
        if(slideindex>=slideimga.length){
            slideindex=0
        }
        showImg(slideindex)
    }
    $('#slideDiv ol li').click(function(){
        var spindex=$(this).index()
        slideindex=spindex
        showImg(slideindex)
    })
    
    var slidetime=setInterval(next,10000)
   
    //秒杀盒子轮播图
    $li=$('.msk_product ul li') 
    $lilength=$li.length
    $liwidth=$li.outerWidth(true)
    // console.log($lilength);

    $('.msk_product ul').width($li.outerWidth(true)*$li.length)
    var index=0
    $('.msk_next').click(function(){
        index+=4   
        if(index>$lilength-4){
            index-=4
            $('.msk_product ul').stop().animate({
                left:-$liwidth*($lilength-4)
                
            })
            console.log(-$liwidth*($lilength-4));
            return
        }
        $('.msk_product ul').stop().animate({
            left:-$liwidth*index
        })
    })
   
    $('.msk_prev').click(function(){
        index-=4
        if(index<0){
            index+=4
            return
        }
            $('.msk_product ul').stop().animate({
                left:- $liwidth*index
            })
      
    });

    
    
    // 请求数据     
   
        $.get("./data/slide.json",function(data){ 
            var slideul=''
            var chidiv=''
            data.forEach(item => {
                var tdata=item.t
                var id=item.id
                var sdata=item.s
                // console.log(sdata);
                var str=''
                str+=`<li><a href="./list.html?id=${id}">`
                for(var i=0;i<tdata.length;i++){
                    str+=`${tdata[i]}&nbsp;`             
                }          
                str+='</a><i class="iconfont icon-arrow-left"></i></li>'
                slideul+=str
                var chistr='<div class="slidechirden">'
                chistr+='<ul>'
                    for(var key in sdata){                
                        chistr+=`<li><a href="./list.html?id=${id}"><img src="${sdata[key][0]}"><span>${sdata[key][1]}</span></a></li>` 
                    }
                    chistr+='</ul></div>'
                    chidiv+=chistr   
                    console.log(id);
            });
            $('.slideleft>ul').html(slideul)
            $('.brchild').append(chidiv)
            $('.brchild .slidechirden').hide()
            $('.slideleft>ul li').mouseenter(function () {
                $('.brchild .slidechirden').eq($(this).index()).show().siblings().hide()
              })
              $('.wks').mouseleave(function () {
                $('.brchild .slidechirden').hide()
                })
        })
    
   
    

    $('.navlist ul li').mouseenter(function () {
        $('.navmenu').stop().slideDown()
      })
      $('.navlist').mouseleave(function () {
        $('.navmenu').stop().slideUp();
      })
    
    
    // 跳转楼层
    $('.floordiv>ul>li').click(function(){
        if($(this).index()==$('.floordiv>ul>li').length-1){
            $('html,body').animate({
                scrollTop:0
            })
            return
        }
        var jltop=$('.floor').eq($(this).index()).offset().top

        $('html,body').stop().animate({
            scrollTop:jltop
        })
    })
    
    